function JSON_Ajax(){
    this.objetoAjax=false;
    this.successCallback=false;
    this.errorCallback=false;

    try {
        this.objetoAjax = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
        this.objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");
        }catch (E){
            this.objetoAjax = false;
        }
    }

    if (!this.objetoAjax && typeof XMLHttpRequest!='undefined') 
        this.objetoAjax = new XMLHttpRequest();
    if(!this.objetoAjax)
        throw "This browser cannot support XMLHttpRequest";
    this.objetoAjax.parent = this;
}

JSON_Ajax.prototype = {
    Post : function(url, args, contentType, successCallback, errorCallback)
    {
        this.successCallback = successCallback;
        this.errorCallback = errorCallback; 
        this.objetoAjax.open('POST', url, true);
        
        this.objetoAjax.onreadystatechange = function(){
        	
            switch(this.readyState){
                case 1: case 2: case 3: 
                    break; 
                case 4:
                    if(this.status == 200 && typeof this.parent.successCallback == "function"){
                        this.parent.successCallback(JSON.parse(this.responseText));
                    }
                    else if(typeof this.parent.errorCallback == "function"){
                        var error = JSON.parse(this.responseText);
                        error.get_message = function(){
                            return this.message;
                        }
                        this.parent.errorCallback(error);
                    }
                    break;
            }    
        } 
        
        this.objetoAjax.setRequestHeader("Content-Type", contentType);
        this.objetoAjax.send(args);
    }
}

function JSON_WebService(url){
    this.URL = url;
    this.oAjax = new JSON_Ajax();

} 

JSON_WebService.prototype = {
    Call : function(method, arguments, onSuccessCallback, onErrorCallback){
        this.oAjax.Post(this.URL + "/" + method, JSON.stringify(arguments),"application/json; charset=utf-8", onSuccessCallback, onErrorCallback);
    }
}